<template>
	<view class="content">
		<view class="block screen-block">
			<view class="screen-item">
				<picker :range="category" @change="bindCategory" range-key="typeName" class="picker category">
					{{category[categoryActive].typeName?category[categoryActive].typeName:''}}
				</picker>
				<view class="iconfont icon-xiasanjiaoxing"></view>
			</view>
		</view>
		<view class="speciaty-block">
			<navigator v-for="(item,index) in list" class="speciaty-item" :url="'/pages/specialties/index?id='+item.id">
				<image :src="item.picUrl" class="speciaty-img" mode="aspectFill"></image>
				<view class="right-block">
					<view class="speciaty-name">{{item.shopName}}</view>
					<view class="address-item">
						<view class="iconfont icon-dingweixiao"></view>
						<view class="address">{{item.address}}</view>
					</view>
					<view class="speciaty-price">{{item.price}}</view>
				</view>
			</navigator>
		</view>
	</view>
</template>

<script>
	import {
		postSpecialtyList,
		getViewListApi
	} from '@/api/speciaties.js';
	export default {
		data() {
			return {
				keyword: '搜索特产',
				custom: null,
				category: [{
						id: 1,
						value: '全部'
					},
					{
						id: 2,
						value: '离我最近'
					},
					{
						id: 3,
						value: '好评优选'
					}
				],
				categoryActive: 0,
				list: []
			}
		},
		methods: {
			bindCategory(e) {
				this.categoryActive = e.detail.value;
				this.speciatiesList()
			},
			bindBusinessArea(e) {
				this.businessAreaActive = e.detail.value;
			},
			speciatiesList() {
				let sortType = this.category[this.categoryActive].id;
				postSpecialtyList({
					page: 0,
					limit: 0,
					sortType
				}).then((res) => {
					if (res.code == 1) {
						if (res.data != null) {
							this.list = res.data;
						}
					} else {
						console.log(res)
					}
				}).catch((res) => {
					console.log(res)
				})
			},
			getViewList() {
				getViewListApi().then((res) => {
					if (res.code == 1) {
						this.category = res.data;
						this.categoryActive = 0;
					} else {
						uni.showToast({
							title: '加载失败',
							mask: true,
						})
					}
				}).catch((res) => {
					uni.hideLoading();
					uni.showToast({
						title: '加载失败',
						mask: true,
					})
				})
			},
		},
		mounted(e) {
			/*自适应微信胶囊按钮*/
			this.custom = this.utils.getCustomNavData();
		},
		onLoad() {
			this.speciatiesList();
			this.getViewList()
		}
	}
</script>

<style lang="scss">
	.content {
		.block.search-block {
			background: $color-primary;
			overflow: hidden;
		}

		.block.screen-block {
			display: flex;
			flex-direction: row;
			background: $color-primary;
			align-items: center;
			padding: 20rpx;

			.screen-item {
				display: flex;
				margin-left: 30rpx;
				color: $color-border-lighter;
				align-items: center;
				font-size: 30rpx;
				flex-grow: 1;

				.picker {
					display: flex;
					justify-content: center;
				}

				.picker.category {
					font-weight: bold;
					font-size: 34rpx;
					color: #fff;
				}

				.iconfont {
					margin-left: 16rpx;
					font-size: 28rpx;
					font-weight: normal;
				}
			}
		}

		.speciaty-block {

			.speciaty-item {
				display: flex;
				position: relative;
				width: calc(100% - 60rpx);
				box-sizing: border-box;
				background-color: #ffffff;
				border-radius: 15rpx;
				box-shadow: 0 0 6px 0px #dadada;
				margin: 30rpx 30rpx 30rpx auto;
				align-items: center;
				padding: 30rpx 0;

				.speciaty-img {
					width: 200rpx;
					height: 200rpx;
					margin: 30rpx;
					border-radius: 10rpx;
					position: absolute;
					margin-top: 30rpx;
					margin-bottom: 30rpx;
				}

				.right-block {
					display: flex;
					flex-direction: column;
					margin: 20rpx;
					margin-left: 250rpx;

					.speciaty-name {
						font-weight: bold;
						font-size: 34rpx;
					}

					.address-item {
						display: flex;
						flex-direction: row;
						align-items: center;
						color: #868686;
						margin: 20rpx 0;

						.iconfont {
							font-size: 26rpx;
						}

						.address {
							font-size: 26rpx;
							margin-left: 10rpx;
						}
					}

					.speciaty-price {
						font-weight: bold;
						font-size: 32rpx;
						color: #e3233f;
					}
				}
			}
		}

		.speciaty-item:last-child {}
	}
</style>